package org.leno.houseHire.dao;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {

	public static void main(String[] args) {
//		Session session = HibernateSessionFactory.getSession();
//		House house = (House) session.get(House.class, 1);
//		HibernateSessionFactory.closeSession();
//		System.out.println(house.getTitle());
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");
		Session session = sessionFactory.openSession();
//		House house = (House) session.get(House.class, 1);
//		System.out.println(house.getTitle());
		List list = session.createQuery("from House").setFirstResult(3).setMaxResults(2).list();
		session.close();
		Iterator it = list.iterator();
		while(it.hasNext()){
			House house =(House) it.next();
			System.out.print(house.getUser().getUname());
			System.out.print(house.getStreet().getSname());
			System.out.println(house.getStreet().getArea().getAname());
		}
	}
}
